﻿using System;

using SwAddinHelpers;
using SwAddinHelpers.Base;
using SwAddinHelpers.Contracts;
using SwAddinHelpers.Attributes;
using SwAddinHelpers.AddinManager;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.ComponentModel.Design;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;

namespace ExternalControls.Menus
{
    [Export(typeof(IExternalCallback))]
    [CommandGroupDefinition("Group3",
            SolidWorks.Interop.swconst.swDocumentTypes_e.swDocPART |
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocASSEMBLY |
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocDRAWING |
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocNONE |
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocSDM,
            true,
            true,
            null)]
    public class MainMenu: IExternalCallback
    {
        //[ImportingConstructor()]
        //public MainMenu([Import] ISwAddinBase owner)
        //{
            // During Composition this constructor is called successfully.
            // However during callbacks, the local 'this' references the code generated type.
        //}

        public dynamic ExternalCallbackContainer
        {
            get { return this; }
        }

        public ISwAddinBase OwnerAddin
        {
            get { return (ISwAddinBase)this.GetType().GetField("OwnerAddin").GetValue(this); }
        }

        [CommandItemCallback("Group3", "DynamicCommand1", null, "Group3_DynamicCommand1")]
        public void CommandCallback2()
        {
            // do some work when command is clicked
        }

        [MenuItemCallback(new SolidWorks.Interop.swconst.swDocumentTypes_e[] {
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocPART ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocASSEMBLY ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocDRAWING ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocNONE ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocSDM} ,
                "dGAF About",
                null,
                null,
                true,
                SolidWorks.Interop.swconst.swMenuIdentifiers_e.swHelpMenu)]
        public void AboutCallback()
        {
            System.Windows.Forms.MessageBox.Show(@"About: Generic Addin Framework R2 ");
        }

        [MenuItemCallback(new SolidWorks.Interop.swconst.swDocumentTypes_e[] {
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocPART ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocASSEMBLY ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocDRAWING ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocNONE ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocSDM},
                "dGAF Help",
                null,
                null,
                true,
                SolidWorks.Interop.swconst.swMenuIdentifiers_e.swHelpMenu, 3)]
        public void HelpCallback()
        {
            System.Windows.Forms.MessageBox.Show(@"Help: Generic Addin Framework R2");
        }

        [MenuItemCallback(new SolidWorks.Interop.swconst.swDocumentTypes_e[] {
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocPART,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocASSEMBLY ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocDRAWING ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocNONE ,
                SolidWorks.Interop.swconst.swDocumentTypes_e.swDocSDM }, 
                "dGAF Manager",
                null,
                null,
                true,
                SolidWorks.Interop.swconst.swMenuIdentifiers_e.swToolsMenu, 4)]
        public void GafManagerCallback()
        {
           AddinManager manager = new AddinManager(OwnerAddin.compositionContainer);
           manager.ShowDialog();
           manager = null;
        }


       
    }
}
